package com.itheima.search.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.search.mapper.CheckgroupMapper;
import com.itheima.search.model.constant.MessageConstant;
import com.itheima.search.model.entity.PageResult;
import com.itheima.search.model.entity.QueryPageBean;
import com.itheima.search.model.pojo.CheckGroup;
import com.itheima.search.model.pojo.CheckItem;
import com.itheima.search.service.CheckgroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Lee
 * @created 2024/5/10
 * @describtion
 */
@Service
public class CheckgroupServiceImpl implements CheckgroupService {

    @Autowired
    public CheckgroupMapper checkgroupMapper;

    /**
     * @param checkGroup
     */
    @Override
    public void save(CheckGroup checkGroup) {
        checkgroupMapper.save(checkGroup);
        List<CheckItem> checkItems = checkGroup.getCheckItems();
        checkgroupMapper.addItems(checkItems);
        checkgroupMapper.addGroupIdAndItemsId(checkGroup.getId(), checkItems.get(MessageConstant.ITEM_ID).getId());
    }

    /**
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult page(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        Page<CheckGroup> page = checkgroupMapper.page(queryPageBean);
        return new PageResult(page.getTotal(), page.getResult());
    }


}
